package com.example.JavaWebApi;
import com.example.JavaWebApi.model.configmodel.JwtProp;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.web.client.RestTemplate;

import java.net.InetAddress;

@EnableConfigurationProperties(JwtProp.class)
@SpringBootApplication
@MapperScan("com.example.JavaWebApi.mapper")
@Slf4j
//@EnableDubbo
//@EnableDiscoveryClient
//@EnableDubboConfig
public class JavaWebApiApplication {
	@SneakyThrows
	public static void main(String[] args) {
		ConfigurableApplicationContext application=SpringApplication.run(JavaWebApiApplication.class, args);
		Environment env = application.getEnvironment();
		String ip = InetAddress.getLocalHost().getHostAddress();
		String port = env.getProperty("server.port");
		//String path = env.getProperty("server.servlet.context-path");
		String envpath = env.getProperty("spring.profiles.active");
		System.out.println(envpath);
		log.info("\n----------------------------------------------------------\n\t" +
				"Application is running! Access URLs:\n\t" +
				"Local: \t\thttp://localhost:" + port  + "/\n\t" +
				"External: \thttp://" + ip + ":" + port  + "/\n\t" +
				"swagger-ui: \thttp://" + ip + ":" + port  + "/swagger-ui/index.html\n\t" +
				"Doc: \t\thttp://" + ip + ":" + port  + "/doc.html\n" +
				"Doc: \t\t 当前加载环境：" + envpath+"\n" +
				"----------------------------------------------------------");
	}
	@Bean
	public RestTemplate restTemplate(RestTemplateBuilder builder) {
		return builder.build();
	}

}
